package com.chy.blog_server.modular.web.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chy.blog_server.core.util.UploadFileUtil;
import com.chy.blog_server.core.util.UploadURLUtil;
import com.chy.blog_server.modular.web.entity.BoFile;
import com.chy.blog_server.modular.web.mapper.BoFileMapper;
import com.chy.blog_server.modular.web.service.IBoFileService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 描述：附件表 service业务层
 * 作者：chenhuiyan
 * 时间：2020/04/09
 */
@Service
@Transactional(readOnly = true)
public class BoFileServiceImpl extends ServiceImpl<BoFileMapper, BoFile> implements IBoFileService {

    private final static Logger logger = LoggerFactory.getLogger(BoFileServiceImpl.class);

    /**
     * 查询列表
     * @param params
     * @return
     */
    public List<Map<String, Object>> list(Map<String, Object> params){
        return baseMapper.list(params);
    }

    /**
     * 查询总数
     * @param params
     * @return
     */
    public int getCount(Map<String, Object> params){
        return baseMapper.getCount(params);
    }

    /**
     * 修改附件的业务id
     * @param serviceId
     * @param orgServiceId
     * @return
     */
    public int updateServiceId(String serviceId, String orgServiceId){
        return baseMapper.updateServiceId(serviceId, orgServiceId);
    }

    /**
     * 查询已删除列表
     * @param params
     * @return
     */
    public List<Map<String, Object>> recycleList(Map<String, Object> params){
        return baseMapper.recycleList(params);
    }

    /**
     * 彻底删除
     * @param id
     * @return
     */
    @Transactional(readOnly = false)
    public int thoroughlyDelete(String id){
        BoFile boFile = this.getById(id);
        int i = baseMapper.thoroughlyDelete(id);;
        boolean flag = UploadFileUtil.deleteOneFile(UploadURLUtil.FILE + boFile.getFileName());
        if(flag){
            logger.info(">>>>>>>>>>>>彻底删除附件成功");
        }else{
            logger.info(">>>>>>>>>>>>彻底删除附件失败");
        }
        return i;
    }

}
